#include "enemy1.h"
#include "config.h"

enemy1::enemy1()
{
    //加载敌人资源
    m_enemy1.load(ENEMY1_PATH);

    //敌人位置
    m_X=GAME_WIDTH;//初始在最右侧
    m_Y=0;

    //敌人状态
    m_Free=true;

    //敌人速度
    m_speed=ENEMY_SPEED;

    //敌人血量
    m_health=ENEMY_HEALTH;

    //敌人边框
    m_Rect.setWidth(m_enemy1.width());
    m_Rect.setHeight(m_enemy1.height());
    m_Rect.moveTo(m_X,m_Y);

}

void enemy1::updatePosition()
{
    //空闲敌人不计算坐标
    if(m_Free)
        return;
    //不空闲的敌人向左移动
    m_X-=m_speed;
    m_Rect.moveTo(m_X,m_Y);
    //敌人到左边界
    if(m_X<=-m_Rect.width())
    {
        m_Free=true;//重置空闲状态
    }
}
